﻿/// Write a program that deletes from given text file all odd lines. The result should be in the same file.

using System;
using System.IO;


namespace c_sh_II_lek_6_files
{
    class zad9
    {
        static void Main()
        {

            int lineNumber = 0;
            string filePath = @"..\..\testStream.txt";
            string output = @"..\..\temp.txt";

            using (StreamReader stream = new StreamReader(filePath))
            {
                using (StreamWriter _out = new StreamWriter(output))
                {
                    string line = stream.ReadLine();
                    while (line != null)
                    {
                        if (lineNumber % 2 == 1)
                        {
                            _out.WriteLine(line);
                        }

                        line = stream.ReadLine();
                        lineNumber++;
                    } 
                }
            }

            File.Delete(filePath);
            File.Copy(output, filePath);
            File.Delete(output);
        }
    }
}
